package com.mall.seckill.job;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Darren
 * @date 2022-10-14 17:01
 * Description：
 */
@Configuration
public class JobCreate {
    @Autowired
    private HotGoodsJob hotGoodsJob;
    @Autowired
    private CoordinatorRegistryCenter coordinatorRegistryCenter;

    @Value("${elaticjob.job.hotGoodsJob.jobName}")
    private String jobName;
    @Value("${elaticjob.job.hotGoodsJob.cron}")
    private String cron;
    @Value("${elaticjob.job.hotGoodsJob.shardingTotalCount}")
    private Integer shardingTotalCount;

    @Bean
    public void startHotGoodsJob() {
        JobConfiguration job = JobConfiguration
                .newBuilder(jobName, shardingTotalCount)
                .cron(cron)
                .overwrite(true)
                .build();
        new ScheduleJobBootstrap(coordinatorRegistryCenter, hotGoodsJob, job).schedule();
    }
}
